<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0034)http://b2core.b24.cn/page/lib_img/ -->
<html xmlns="http://www.w3.org/1999/xhtml" class="hb-loaded"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

  <title>图片类</title>
  <meta name="keywords" content="图片类">
  <meta name="description" content="图片类">
  <link href="./图片类_files/default.css" rel="stylesheet" type="text/css" media="screen">
  <!--<base href="http://b2core.b24.cn/">--><base href=".">
<style id="style-1-cropbar-clipper">/* Copyright 2014 Evernote Corporation. All rights reserved. */
.en-markup-crop-options {
    top: 18px !important;
    left: 50% !important;
    margin-left: -100px !important;
    width: 200px !important;
    border: 2px rgba(255,255,255,.38) solid !important;
    border-radius: 4px !important;
}

.en-markup-crop-options div div:first-of-type {
    margin-left: 0px !important;
}
</style></head>
<body huaban_collector_injected="true">
<div id="wrapper">
  <div id="page-content">
    <div id="header-wrapper">
      <div id="header">
        <div id="logo">
          <h1><a href="http://b2core.b24.cn/"><img src="./图片类_files/20120501081847_44850.png" alt="b2Core"></a></h1>
          <p>轻量 php MVC 架构</p>
        </div>
      </div>
    </div>
    <!-- end #header -->
    <div id="menu-wrapper">
      <div id="menu">
        <ul>
              <li class="first"><a href=""><span>首页</span></a></li><li><a href="http://b2core.b24.cn/page/help/"><span>使用入门</span></a></li><li><a href="http://b2core.b24.cn/page/code/"><span>代码及注释</span></a></li><li><a href="http://b2core.b24.cn/page/lib/"><span>类库</span></a></li><li><a href="http://alpaca.b24.cn/bbs/forum/13/" target="_blank"><span>讨论</span></a></li>	
        </ul>
      </div>
    </div>
    <!-- end #menu -->
    <div id="banner"></div>
    <div class="padding">
      <div id="breadcrumb" class="post">
         <a href="http://b2core.b24.cn/">首页</a> »  <a href="http://b2core.b24.cn/page/lib/">类库</a> »       </div>
      <div class="post">
      <h1>图片类 : img.php </h1>
<div>下载 <a href="http://b2core.googlecode.com/files/img.php" target="_blank">http://b2core.googlecode.com/files/img.php</a> </div>
<div class="important"> 图片上传、生成缩略图 </div>
<div class="notice"> <code><span style="color: #000000">
<span style="color: #0000BB">&lt;?
<br></span><span style="color: #FF8000">//示例：&nbsp;上传图片
<br></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">example</span><span style="color: #007700">()&nbsp;
<br>{
<br>&nbsp;&nbsp;</span><span style="color: #0000BB">$img&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">load</span><span style="color: #007700">(</span><span style="color: #DD0000">'lib/img'</span><span style="color: #007700">);
<br>&nbsp;&nbsp;</span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">save_file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">time</span><span style="color: #007700">().</span><span style="color: #DD0000">'jpg'</span><span style="color: #007700">;
<br>&nbsp;&nbsp;</span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">upload</span><span style="color: #007700">(</span><span style="color: #0000BB">$_FILE</span><span style="color: #007700">[</span><span style="color: #0000BB">file</span><span style="color: #007700">]);&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;完成图片上传
<br></span><span style="color: #007700">}
<br>
<br></span><span style="color: #FF8000">//生成缩略图
<br></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">thumb</span><span style="color: #007700">(</span><span style="color: #0000BB">$size&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">300&nbsp;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">)
<br>{
<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'img/big.jpg'</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;原图地址
<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$img&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">load</span><span style="color: #007700">(</span><span style="color: #DD0000">'lib/img'</span><span style="color: #007700">);
<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">filename&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">;
<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">file_tmp_name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">;
<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">save_file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'thumb/'</span><span style="color: #007700">.</span><span style="color: #0000BB">$size</span><span style="color: #007700">.</span><span style="color: #DD0000">'/'</span><span style="color: #007700">.</span><span style="color: #0000BB">$file</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//储存地址
<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">limit_w&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$size</span><span style="color: #007700">;
<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$img</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">create</span><span style="color: #007700">();&nbsp;</span><span style="color: #FF8000">//生成缩略图
<br></span><span style="color: #007700">}</span>
</span>
</code> </div>
      </div>
      <div class="clear"> </div>
    </div>
    <!-- end #content -->
  <div class="clear"> </div>
</div>
  <div id="footer">
    <p>Powered by <a href="http://alpaca.b24.cn/">Alpaca</a></p>
  </div>
<!-- end #footer -->
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fd9630d6f04c9cd79d5755f7241fa6dc0' type='text/javascript'%3E%3C/script%3E"));
</script><script src="./图片类_files/h.js" type="text/javascript"></script><a href="http://tongji.baidu.com/hm-web/welcome/ico?s=d9630d6f04c9cd79d5755f7241fa6dc0" target="_blank"><img border="0" src="./图片类_files/21.gif" width="20" height="20"></a>

</div></body></html>